package com.yang.thread.syn;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author yds
 * @program thread-study
 * @description 抢占共享区变量，导致的线程不安全
 * @create 2020-09-22 16:37
 **/
public class ThreadNoSafe implements Runnable {
    private  Integer i=10;
    @Override
    public synchronized void run() {
        while (i > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "抢到第" + (11-i) + "张票");
            i--;

        }
    }

    public static void main(String[] args) {
        ThreadNoSafe t1=new ThreadNoSafe();
        new Thread(t1,"小张").start();
        new Thread(t1,"小杨").start();
     }


}